window.app = app = angular.module('app',['ngRoute','ngResource','mgcrea.ngStrap', 'ngProgress'])

app.config ['$routeProvider', ($routeProvider)->
	$routeProvider.otherwise
		redirectTo : '/blog/list'
]

app.service 'progress', ['$rootScope', 'ngProgress', ($rootScope, ngProgress)->
	$rootScope.$on 'event:request.start', ()->
		ngProgress.reset()
		ngProgress.start()
	$rootScope.$on 'event:request.end', ()->
		setTimeout ()->
			ngProgress.complete()
		,300
]

app.config ['$httpProvider',  ($httpProvider)->
	$httpProvider.interceptors.push  ($rootScope)->
		return {
			'request': (config)->
				$rootScope.$broadcast('event:request.start')
				return config

			'response': (config)->
				$rootScope.$broadcast('event:request.end')
				return config
		}
]



app.controller 'NavigationController', ['$rootScope', '$scope' , '$route', 'ngProgress','progress'
	, ($rootScope,  $scope, $route, ngProgress, progress)->
		$rootScope.$on '$locationChangeStart', ()->
			ngProgress.start()
		$rootScope.$on '$locationChangeSuccess', ()->
			currentPath = $route.current.originalPath?.split('/')[1]
			$scope.currentMenu = {}
			$scope.currentMenu[currentPath] = 'active'
			ngProgress.complete()

		$rootScope.ACTIVITY_STATUS = 
			'0': 
				text:'隐藏'
				color:'default'
				value:'0'
			'1':
				text:'开始报名'
				color:'success'
				value:'1'
			'2':
				text:'结束'
				color:'info'
				value:'2'
			'3':
				text:'取消'
				color:'danger'
				value:'3'



]